package com.banciyuan.wallpaper.page;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.banciyuan.wallpaper.R;
import com.banciyuan.wallpaper.base.BaseActivity;
import com.banciyuan.wallpaper.setting.SettingConfig;

/**
 * Created by squall on 2016/7/29.
 */
public class SelectActivity extends BaseActivity implements View.OnClickListener {

    private TextView girl;
    private TextView boy;
    private TextView title;
    private LinearLayout select_container;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        OnInitUI();
        OnInitAction();
    }

    @Override
    protected void OnInitUI() {
        title = (TextView) findViewById(R.id.set_title);
        boy = (TextView) findViewById(R.id.set_boy);
        girl = (TextView) findViewById(R.id.set_girl);
        select_container = (LinearLayout) findViewById(R.id.select_container);
    }

    @Override
    protected void OnInitAction() {
        boy.setOnClickListener(this);
        girl.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.set_boy:
                SettingConfig.WriteSettingString(getBaseContext(), SettingConfig.SEX, SettingConfig.BOY);
                break;
            case R.id.set_girl:
                SettingConfig.WriteSettingString(getBaseContext(), SettingConfig.SEX, SettingConfig.GIRL);
                break;
        }
        Intent intent = new Intent(getBaseContext(), MainActivity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.umeng_socialize_fade_in, R.anim.umeng_socialize_fade_out);
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            select_container.post(new Runnable() {
                @Override
                public void run() {
                    if (title.getVisibility() == View.GONE) {
                        title.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), R.anim.fly_top_fade_in));
                        select_container.startAnimation(AnimationUtils.loadAnimation(getBaseContext(), R.anim.fly_bottom_fade_in));
                        title.setVisibility(View.VISIBLE);
                        select_container.setVisibility(View.VISIBLE);
                    }
                }
            });
        }
    }


}
